﻿using LanguagePolish.Base;
using LanguagePolish.EntityModel;
using LanguagePolish.Models;
using LanguagePolish.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace LanguagePolish.ViewModels
{
    public class CalendarViewModel : BaseViewModel
    {
        private CalendarModel model;

        public CalendarViewModel()
        {
            model = new CalendarModel();
        }

        public void AddLesson(DateTime date)
        {
            Lesson lesson = new Lesson();
            lesson.LessonDate = date;
            AddLessonView dlg = new AddLessonView(lesson);
            bool? res = dlg.ShowDialog();
            if (res == true)
            {
                model.AddLesson(lesson);
            }
        }
        
        public void EditLesson(Lesson lesson)
        {
            AddLessonView dlg = new AddLessonView(lesson, true);
            bool? res = dlg.ShowDialog();
            if (res == true)
            {
                model.SaveChanges();
            }
            else
            {
                model.RollbackClass(lesson);
                lesson.NotifyAll();
            }
        }

        public void RemoveLesson(Lesson lesson)
        {
            MessageBoxResult res = MessageBox.Show("Delete this lesson?", "Attention", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (res == MessageBoxResult.Yes)
            {
                model.RemoveLesson(lesson);
            }
        }
    }
}
